home *** CD-ROM | disk | FTP | other *** search
- /* Shorthand notation. */
- using System;
-
- namespace Chapter2 {
- class Class1 {
- static void Main() {
- string Input;
- int iVariable1, iVariable2, iVariable3, iCharacter;
- // Note: later we'll learn techniques that will allow us
- // to read partial bits of info, but until then we'll still
- // want to enter each number with a return statement
- Console.Write("\n Enter two numbers: ");
- Input = Console.ReadLine();
- iVariable1 = int.Parse(Input);
- Input = Console.ReadLine();
- iVariable2 = int.Parse(Input);
- iVariable3 = iVariable1;
-
- Console.WriteLine("\n Enter one symbol: \n addition (+) "
- + "\n subtraction (-) \n multiplication (*)"
- + "\n division (/), or \n remainder (%): ");
- iCharacter = Console.Read();
-
- if (iCharacter == '+') {
- iVariable1 = iVariable1 + iVariable2;
- Console.WriteLine("\n Your longhand sum is "
- + iVariable1);
- iVariable3 += iVariable2;
- Console.WriteLine("\n Your shorthand sum is also "
- + iVariable3);
- }
-
- if (iCharacter == '-') {
- iVariable1 = iVariable1 - iVariable2;
- Console.WriteLine("\n Your longhand difference is "
- + iVariable1);
- iVariable3 -= iVariable2;
- Console.WriteLine("\n Your shorthand difference is "
- + iVariable3);
- }
-
- if (iCharacter == '*') {
- iVariable1 = iVariable1 * iVariable2;
- Console.WriteLine("\n Your longhand product is "
- + iVariable1);
- iVariable3 *= iVariable2;
- Console.WriteLine("\n Your shorthand product is "
- + iVariable3);
- }
-
- if (iCharacter == '/') {
- iVariable1 = iVariable1 / iVariable2;
- Console.WriteLine ("\n Your longhand quotient is "
- + iVariable1);
- iVariable3 /= iVariable2;
- Console.WriteLine ("\n Your shorthand quotient is "
- + iVariable3);
- }
-
- if (iCharacter == '%') {
- iVariable1 = iVariable1 % iVariable2;
- Console.WriteLine("\n Your longhand remainder is "
- + iVariable1);
- iVariable3 %= iVariable2;
- Console.WriteLine("\n Your shorthand remainder is "
- + iVariable3);
- }
- }
- }
- }
-